<?php 

function random() {
  return (float)rand()/(float)getrandmax();
}

function JS_charCodeAt($str, $index){
    $char = mb_substr($str, $index, 1, 'UTF-8');
    if (mb_check_encoding($char, 'UTF-8'))
    {
        $ret = mb_convert_encoding($char, 'UTF-32BE', 'UTF-8');
        return hexdec(bin2hex($ret));
    } else {
        return null;
    }
}



function getKey($user_id){
	$securityKey = floor(random()*1e8);
	$str = time().':'.$user_id.':'.$securityKey;
	return $str;
}

function addpadding($string, $blocksize = 8) {

    $len = strlen($string);

    $pad = $blocksize - ($len % $blocksize);

    $string .= str_repeat(chr($pad), $pad);

    return $string;

}


//$value =  getKey("4123412341234");

$value = "1618885206616:4123412341234:48354949";
$key = "DkOliWvFNR7C4WvR";
$iv = "GQWKUE2CVGOOBKXU";

$encrypt = '646286b0b1bddffc5ea8c9e4fdf6080d931e9531b155e56d13f0b8cc82785e34854254fe';

$a = openssl_encrypt(addpadding($value), 'AES-128-CFB', $key, $options = OPENSSL_ZERO_PADDING, $iv);
var_dump($a);

//$b = openssl_decrypt($a, 'AES-128-CFB', $key, $options = OPENSSL_ZERO_PADDING, $iv);
//var_dump($b);


